/*
Copyright (c) 2017-2019, 武汉市嘉仪尔科技有限公司（Wuhan jiayier Technology Co.,Ltd)

Email: 707777212@qq.com
Web: www.o2mation.cn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef PARSER_H
#define PARSER_H

#include "config.h"

enum PARSER_TOKEN
{
    TOKEN_INVALID = 0,
    TOKEN_OK,

    TOKEN_KEYWORD_PAIR,
    TOKEN_TRAILER_NAME,
    TOKEN_TRAILER_LIST,
    TOKEN_TRAILER_FUNC,
    TOKEN_DEFAULT_ARG,

    TOKEN_MAIN,
    TOKEN_OUT_OF_MEM,
    TOKEN_FUNCTION,
    TOKEN_END,
    TOKEN_IF,
    TOKEN_JUMP,
    TOKEN_JUMP_END,
    TOKEN_ELSE_IF,
    TOKEN_ELSE,
    TOKEN_WHILE,
    TOKEN_FOR,
    TOKEN_BREAK,
    TOKEN_CONTINUE,
    TOKEN_RETURN,
    TOKEN_RAISE,
    TOKEN_IMPORT,
    TOKEN_IMPORT_AS,
    TOKEN_GLOBAL,
    TOKEN_NONLOCAL,
    TOKEN_CLASS,
    TOKEN_INHERIT,
    TOKEN_NONE,
    TOKEN_TRUE,
    TOKEN_FALSE,
    TOKEN_VAR,
    TOKEN_VARM,
    TOKEN_VARP,
    TOKEN_CALL,
    TOKEN_CALLP,
    TOKEN_SDN,
    TOKEN_SUP,

    TOKEN_ASSIGN,
    TOKEN_ADD_ASSIGN,
    TOKEN_SUB_ASSIGN,
    TOKEN_MUL_ASSIGN,
    TOKEN_DIV_ASSIGN,
    TOKEN_MOD_ASSIGN,
    TOKEN_AND_ASSIGN,
    TOKEN_OR_ASSIGN,
    TOKEN_XOR_ASSIGN,
    TOKEN_LSHIFT_ASSIGN,
    TOKEN_RSHIFT_ASSIGN,

    TOKEN_ASSIGN_P,
    TOKEN_ADD_ASSIGN_P,
    TOKEN_SUB_ASSIGN_P,
    TOKEN_MUL_ASSIGN_P,
    TOKEN_DIV_ASSIGN_P,
    TOKEN_MOD_ASSIGN_P,
    TOKEN_AND_ASSIGN_P,
    TOKEN_OR_ASSIGN_P,
    TOKEN_XOR_ASSIGN_P,
    TOKEN_LSHIFT_ASSIGN_P,
    TOKEN_RSHIFT_ASSIGN_P,
    TOKEN_LT,
    TOKEN_GT,
    TOKEN_EQ,
    TOKEN_GTE,
    TOKEN_LTE,
    TOKEN_NE,
    TOKEN_IN,
    TOKEN_NOT,
    TOKEN_ADD,
    TOKEN_SUB,
    TOKEN_MUL,
    TOKEN_DIV,
    TOKEN_MOD,
    TOKEN_AND,
    TOKEN_OR,
    TOKEN_XOR,
    TOKEN_LSHIFT,
    TOKEN_RSHIFT,

    TOKEN_NAME,
    TOKEN_ARG,
    TOKEN_TUPLE,
    TOKEN_DICT,
    TOKEN_LIST,
    TOKEN_LIST_INDEX,
    TOKEN_INTEGER,
    TOKEN_DOUBLE,
    TOKEN_LONG,
    TOKEN_INDENT,
    TOKEN_STRING,
    TOKEN_EOF,
    TOKEN_LINE,
};


typedef struct parser{
    int val_count;
    uint8_t token;
    uint8_t flag;
    uint16_t row;
    double num;
    char name[100];
    const char * input;
    int input_len;
    int index;
    uint8_t * token_buf;
    int token_buf_index;
    int token_buf_size;
    int last_indent;
}parser_t;

void parser_init(parser_t * p, void * e, const char *input, int size);
int parser_run(parser_t *p);
int parser_token_debug(parser_t *p, uint8_t * buf, int index);

#endif
